package com.example.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@ToString
public class OrderConfirmVo {

    @Getter @Setter
    List<MemberAddressVo> address;
    @Getter @Setter
    List<OrderItemVo> items;
    @Getter @Setter
    Integer integration;

    BigDecimal total;
    BigDecimal payPrice;
    @Getter @Setter
    Map<Long,Boolean> stocks;

    @Getter@Setter
    String token;

    Integer count;

    //防重令牌
    String orderToken;

    public Integer getCount() {
        Integer i = 0;
        if(items!=null){
            for (OrderItemVo item : items){
                i+=item.getCount();
            }
        }
        return i;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");

        if(items != null && items.size() > 0)
        for (OrderItemVo item : items) {
            sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal("0");

        if(items != null && items.size() > 0)
            for (OrderItemVo item : items)
                sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
            return sum;
    }
}
